﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
/**
 * 虽然是已过时的东西，但是如果是QQ应用客户，我们无法找到用户的邮箱，所以还是只能通过短消息来和用户进行沟通
 * 
 * */
namespace CMSService
{
    /// <summary>
    /// 短消息
    /// </summary>
    public class MessageService : ICMS.IMessage
    {
        DavidDB.ADO.DBManager db = null;
        private MessageService()
        {
            db = new DavidDB.ADO.DBManager();
        }
        public MessageService(DavidDB.ADO.DBManager db)
        {
            this.db = db;
        }





        /// <summary>
        /// 获取一个网站短消息
        /// </summary>
        /// <param name="id">短消息编号</param>
        /// <returns>网站短消息，如果没有，返回Null</returns>
        public CMSModel.Message GetModel(int id)
        {
            CMSModel.Message returnValue = new CMSModel.Message();
            returnValue.Id = id;
            returnValue = db.GetModel(returnValue);
            return returnValue;
        }
        /// <summary>
        /// 删除一个网站短消息
        /// </summary>
        /// <param name="id">短消息编号</param>
        /// <returns>成功删除，返回0，没有当前短消息，返回-1</returns>
        public int Delete(int id)
        {
            int returnValue = (int)CMSModel.DBOperatorStatus.Success;
            CMSModel.Message model = new CMSModel.Message();
            model.Id = id;
            db.Delete(model);
            return returnValue;
        }
        /// <summary>
        /// 增加一个网站短消息
        /// </summary>
        /// <param name="announcement">网站短消息实体</param>
        /// <returns>增加成功，返回0</returns>
        public int Insert(CMSModel.Message message)
        {
            int returnValue = (int)CMSModel.DBOperatorStatus.Success;
            db.Insert(message);
            return returnValue;
        }
        /// <summary>
        /// 编辑一个短消息
        /// </summary>
        /// <param name="announcement">编辑完成的短消息</param>
        /// <returns>编辑成功，返回0</returns>
        public int Edit(CMSModel.Message message)
        {
            int returnValue = (int)CMSModel.DBOperatorStatus.Success;
            db.Edit(message);
            return returnValue;
        }
        /// <summary>
        /// 到底最新的count条记录
        /// </summary>
        /// <param name="count">查询条数</param>
        /// <returns>如果记录足够多，返回count条，否则，返回所有记录</returns>
        public List<CMSModel.Message> GetList(int count)
        {
            List<CMSModel.Message> lists = new List<CMSModel.Message>();
            var query = db.GetTopList(count, new CMSModel.Message());
            foreach (CMSModel.Message model in query)
            {
                lists.Add(model);
            }
            return lists;
        }
    }
}
